package org.restoran.service;


import java.io.Serializable;

/**
 *
 * Base service for general service methods
 */

public interface CrudService<T, ID extends Serializable> {

    /**
     * Retrieves an entity by its id.
     *
     * @param id must not be {@literal null}.
     * @return the entity with the given id or {@literal null} if none found
     * @throws IllegalArgumentException if {@code id} is {@literal null}
     */
    T findOne(ID id);


    Iterable<T> findAll();

    /**
     * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the
     * entity instance completely.
     *
     * @param newEntity entity to save
     * @return the saved entity
     * @throws ServiceException if some exception occurs in "business-logic" flow
     * @throws IllegalArgumentException if {@code newEntity} is {@literal null}
     */
    T save(T newEntity);


    /**
     * Deletes a given entity.
     *
     * @param deleted
     * @throws IllegalArgumentException in case the given entity is (@literal null}.
     */
    void delete(T deleted);


    /**
     * Deletes the entity with the given id.
     *
     * @param deletedId must not be {@literal null}.
     * @throws IllegalArgumentException in case the given {@code id} is {@literal null}
     */
    void delete(ID deletedId);
}
